import config from '@/config/index.js'
import store from '@/store/index.js'

const assets = {

	load_img() {
		return '/static/common/loading-icon.jpg'
	},

	load_err() {
		return '/static/common/loading-err.jpg'
	},

	/**
	 * 加载指定文件名的资源（资源文件名必须是绝对路径)
	 * @param {String} fileName
	 */
	img(fileName, width) {
		if (fileName == undefined || fileName == null || fileName.length <= 0) {
			return assets.load_img();
		}
		if (fileName.toLowerCase().indexOf('/static/images/') == 0) {
			if (store.getters.appConfig) {
				return config.is_from_local ? fileName : store.getters.appConfig.assetsRootUrl + fileName
			}else {
				return config.is_from_local ? fileName : 'https://lbb.ejiakanghu.cn/hbewuser' + fileName
			}
		}
		if (fileName.toLowerCase().indexOf('http') != -1 || fileName.toLowerCase().indexOf('https') != -1 ||
			fileName.toLowerCase().indexOf('base64') != -1 || fileName.toLowerCase().indexOf('/static/') == 0) {
			if (fileName.toLowerCase().indexOf('https://litemall-admin-001.oss-cn-hangzhou.aliyuncs.com') != -1) {
				let imgSrc = fileName.split('?')[0]
				if (width == undefined || width <= 0) {
					return imgSrc
				}
				return `${imgSrc}?x-oss-process=image/resize,w_${width},m_lfit/quality,q_80`
			}
			return fileName;
		}
		return assets.load_img();
	},

}

export default assets
